package com.ybvtc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ybvtc.domain.Book;
import com.ybvtc.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.swing.*;
import java.util.List;

@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookService bookService;

    @RequestMapping("/selectNewbooks")
    public String selectNewbooks(Model model) {
        IPage<Book> pageResult = bookService.selectNewbooks();
        System.out.println(pageResult.getRecords());
        if (pageResult != null) {
            System.out.println("已收到数据");
//            model.addAttribute("users", pageResult.getRecords());
        } else {
            System.out.println("没查询到数据");

        }
/*        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("books",pageResult.getRecords());
        modelAndView.setViewName("books_new");*/
        model.addAttribute("books", pageResult.getRecords());
        return "books_new";
    }

    @GetMapping("/findById")
    public String findById(Book book) {
        bookService.findById(book);
    }
}
